package com.alex.algorithm.medium;

public class ContainerWithMostWater {
    /**
     *  [1,8,6,2,5,4,8,3,7]
     * @param args
     */
    public static void main(String[] args) {
        System.out.println(getMostWater(new int[]{ 1,8,6,2,5,4,8,3,7}));
    }

    private static int getMostWater(int[] array) {
        int left = 0;
        int right = array.length - 1;
        int max = 0;
        while(left < right) {
            int area = Math.abs(left-right) * Math.min(array[left],array[right]);
            if (area > max) {
                max = area;
            }
            if (array[left] < array[right]) {
                ++left;
            }else {
                --right;
            }
        }
        return max;
    }
}
